let cookie = {
    set(key,value,json = {}){
        //处理主键值对
        let cookie_str = encodeURIComponent(key) + '=' + encodeURIComponent(value);
        //是否有有效期
        if(!isNaN(json.expires)){
            //创建日期对象
            let date = new Date();
            //n天后
            date.setDate(date.getDate() + json.expires);
            //设置cookie有效期
            cookie_str += ';expires=' + date;
        }
        //路径
        if(json.path){
            cookie_str += ';path=' + json.path;
        }
        //创建cookie
        document.cookie = cookie_str;
    },
    get(key){
        let arr = document.cookie.split('; ');
        for(let i = 0,len = arr.length;i < len;i ++){
            let list = arr[i].split('=');
            if(encodeURIComponent(key) === list[0]){
                return decodeURIComponent(list[1]);
            }
        }
    },
    del(key,json = {}){
        if(json.path){ //修改过路径 
            document.cookie = `${encodeURIComponent(key)}=;expires=${new Date(0)};path=${json.path}`;
        }else{
            document.cookie = `${encodeURIComponent(key)}=;expires=${new Date(0)}}`;
        }
    },
    convertObj(str){
        if(!str){
            return {};
        }
        return JSON.parse(str);
    }
}